package table.col;

import java.util.List;

import table.Col;
import table.DataTable;
import table.node.BaseNode;
import table.node.DataNode;

public class FormulaA2BCol extends ResultA2BCol {
	protected DataNode getColValueFromBTable(DataTable bTable){
		List<Col> bCols = this.getTableColsByNames(this.getBTable(), this.getDstColNames());
		DataNode node = new BaseNode();
		if(null != bCols && 1 < bCols.size()
				&& null != bCols.get(0) && null != bCols.get(1)){
			Col firstCol = bCols.get(0);
			Col secondCol = bCols.get(1);
			List<DataNode> firstDataList = firstCol.getDataList();
			List<DataNode> secondDataList = secondCol.getDataList();
			double result = 0.0;
			
			if(firstDataList.size() > 0 && firstDataList.get(0) != null &&
					secondDataList.size() > 0 && secondDataList.get(0) != null){
				result = Double.parseDouble(firstDataList.get(0).getNodeValue().toString()) * Double.parseDouble(secondDataList.get(0).getNodeValue().toString());
				node.setNodeValue(result);
				return node;
			}
		}
		node.setNodeValue(0);
		return node;
	}

}
